package com.ljkj.blockpay.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.bumptech.glide.Glide;
import com.kongzue.baseokhttp.util.JsonMap;
import com.ljkj.blockpay.R;
import com.ljkj.blockpay.basedata.BaseActivity;
import com.ljkj.blockpay.databinding.ActivityTradingparticularsBinding;
import com.ljkj.blockpay.presenter.TradingParticularsPresenter;
import com.ljkj.blockpay.presenter.inter.TradingInter;
import com.ljkj.blockpay.util.ToggleToActivity;
import com.ljkj.blockpay.widget.ClickListener;

import java.text.SimpleDateFormat;
import java.util.Date;


/**
 *
 * 交易详情页面
 */
public class TradingParticularsActivity extends BaseActivity<ActivityTradingparticularsBinding,TradingParticularsPresenter> implements TradingInter.TradingInterView,ClickListener {

    public static final String TAG_ORDERTYPE = "TradingParticularsActivity.tag_ordertype";
    public static final String TAG_ORDERID = "TradingParticularsActivity.tag_ordertyid";
    private int orderType;
    private String orderId;
    private String createTime;
    private String exchangeRateDesc;
    private boolean fromMe;
    private String headUrl;
    private String networkType;
    private String orderIds;
    private String orderStatus;
    private String orderTypes;
    private String originAccount;
    private String originActualAmount;
    private String originAmount;
    private String originCurrency;
    private String originServiceAmount;
    private String originUserName;
    private String remark;
    private String targetAccount;
    private String targetActualAmount;
    private String targetAddress;
    private String targetAmount;
    private String targetCurrency;
    private String targetServiceAmount;
    private String targetUserName;
    private String  time;
    @Override
    public int initContentView() {
        return R.layout.activity_tradingparticulars;
    }

    @Override
    protected TradingParticularsPresenter createPresenter() {
        return new TradingParticularsPresenter(this,this);
    }

    @Override
    protected void init(Bundle savedInstanceState) {

        binding.setOnClick(this::onClick);
//        binding.ivFirst.setImageResource(R.mipmap.progress_selected);
        binding.tvTitle.setLeftBtnListener(new ClickListener() {
            @Override
            public void onClick(View view) {
                ToggleToActivity.toMainActivity(TradingParticularsActivity.this);
            }
        });
        binding.tvTitle.setTitleContent(R.string.tradingparticulars);
    }

    @Override
    protected void initData() {
        super.initData();
        orderType = getIntent().getIntExtra(TAG_ORDERTYPE,0);
        orderId = getIntent().getStringExtra(TAG_ORDERID);
        Log.d("XIAOYU----",orderType+"");
        Log.d("XIAOYU----","12345"+orderId+"");
        getPresenter().orderDetail(orderId);

    }



    @Override
    public void onClick(View view) {


    }

    @Override
    public void orderDetailSuccess(JsonMap jsonMap) {
        createTime = jsonMap.getString("createTime");
        exchangeRateDesc = jsonMap.getString("exchangeRateDesc");
        fromMe = jsonMap.getBoolean("fromMe");
        headUrl = jsonMap.getString("headUrl");
        networkType = jsonMap.getString("networkType");
        orderIds = jsonMap.getString("orderId");
        orderStatus = jsonMap.getString("orderStatus");
        orderTypes = jsonMap.getString("orderType");
        originAccount = jsonMap.getString("originAccount");
        originActualAmount = jsonMap.getString("originActualAmount");
        originAmount = jsonMap.getString("originAmount");
        originCurrency = jsonMap.getString("originCurrency");
        originServiceAmount = jsonMap.getString("originServiceAmount");
        originUserName = jsonMap.getString("originUserName");
        remark = jsonMap.getString("remark");
        targetAccount = jsonMap.getString("targetAccount");
        targetActualAmount = jsonMap.getString("targetActualAmount");
        targetAddress = jsonMap.getString("targetAddress");
        targetAmount = jsonMap.getString("targetAmount");
        targetCurrency = jsonMap.getString("targetCurrency");
        targetServiceAmount = jsonMap.getString("targetServiceAmount");
        targetUserName = jsonMap.getString("targetUserName");

        long l = Long.parseLong(createTime);
        time = conventDateStrByPattern(new Date(l), "yyyy-MM-dd HH:mm:ss");
        Glide.with(TradingParticularsActivity.this).load(headUrl).into(binding.ivIcon);

        switch (orderType){
            //充值
            case 1:
                //创建时间
                binding.rlCleationtime.setVisibility(View.VISIBLE);
                //订单号
                binding.rlOrdernumber.setVisibility(View.VISIBLE);
                binding.tvTimes.setText(time);
                binding.tvOrder.setText(exchangeRateDesc);

                break;
            //转账
            case 2:
                //fromme
                // 收款方式

                binding.tvRecharge.setText("转账");
                binding.tvNum.setText(originActualAmount);
                binding.tvUnit.setText(originCurrency);
                binding.rlPaymentterm.setVisibility(View.VISIBLE);
                //对方账号
                binding. rlReciprocalaccountnumber.setVisibility(View.VISIBLE);
                //收款账号
                binding.rlShroffaccountnumber.setVisibility(View.GONE);
                //创建时间
                binding.rlCleationtime.setVisibility(View.VISIBLE);
                //订单号
                binding.rlOrdernumber.setVisibility(View.VISIBLE);
                //备注
                binding.rlRemark.setVisibility(View.VISIBLE);

                if (fromMe){
                    binding.tvTerm.setText(originCurrency);
                    binding.tvReciprocalaccount.setText(targetAccount);
                } else {
                    binding.tvTerm.setText(targetCurrency);
                    binding.tvReciprocalaccount.setText(originAccount);
                }

                binding.tvTimes.setText(time);
                binding.tvOrder.setText(orderIds);
                binding.tvRemarktext.setText(remark);
                break;
            //提币
            case 3:
                binding.tvRecharge.setText("提币");
                binding.tvNum.setText(targetAmount);
                binding.tvUnit.setText(originCurrency);
                //提币地址
                binding.rlMentionmoneyaddress.setVisibility(View.VISIBLE);
                //到账数量
                binding.rlAccountnumber.setVisibility(View.VISIBLE);
                //手续费
                binding.rlServicecharge.setVisibility(View.VISIBLE);
                //链类型
                binding.rlChaintype.setVisibility(View.VISIBLE);
                //创建时间
                binding.rlCleationtime.setVisibility(View.VISIBLE);
                //订单号
                binding.rlOrdernumber.setVisibility(View.VISIBLE);
                binding.tvMentionmoney.setText(targetAddress);
                binding.tvAccountnum.setText(targetAmount);
                binding.tvServicethb.setText(originServiceAmount);
                binding.tvChain.setText(networkType);
                binding.tvTimes.setText(time);
                binding.tvOrder.setText(orderIds);
                break;
            //付款
            case 4:
                binding.tvRecharge.setText("付款");
                binding.tvNum.setText(targetActualAmount);
                binding.tvUnit.setText(originCurrency);
                //付款金额
                binding.rlPaymentamount.setVisibility(View.VISIBLE);
                //手续费
                binding.rlServicecharge.setVisibility(View.VISIBLE);
                //付款方式
                binding.rlPaymentmethod.setVisibility(View.VISIBLE);
                //对方账号
                binding. rlReciprocalaccountnumber.setVisibility(View.VISIBLE);
                //备注
                binding.rlRemark.setVisibility(View.VISIBLE);
                //创建时间
                binding.rlCleationtime.setVisibility(View.VISIBLE);
                //订单号
                binding.rlOrdernumber.setVisibility(View.VISIBLE);

                binding.tvPaymentnum.setText(originActualAmount);
                binding.tvServicethb.setText(originServiceAmount);
                binding.tvPayments.setText(originCurrency);
                binding.tvRemarktext.setText(remark);
                binding.tvTimes.setText(time);
                binding.tvOrder.setText(orderIds);
                break;
            //兑换
            case 5:
                binding.tvNum.setText(originActualAmount);
                binding.tvUnit.setText(originCurrency);
                //消耗金额
                binding.rlConsumptionamount.setVisibility(View.VISIBLE);
                //汇率
                binding.rlParities.setVisibility(View.VISIBLE);
                //手续费
                binding.rlServicecharge.setVisibility(View.VISIBLE);
                //付款方式
                binding.rlPaymentmethod.setVisibility(View.VISIBLE);
                //创建时间
                binding.rlCleationtime.setVisibility(View.VISIBLE);
                //订单号
                binding.rlOrdernumber.setVisibility(View.VISIBLE);

                binding.tvConsumption.setText(originActualAmount);
                binding.tvParitiesexchange.setText(exchangeRateDesc);
                binding.tvServicethb.setText(targetServiceAmount);
                binding.tvPayments.setText(originCurrency);

                binding.tvTimes.setText(time);
                binding.tvOrder.setText(orderIds);

                break;

            default:
                break;

        }
    }



    public static String conventDateStrByPattern(Date date, String pattern) {
        if (date == null) {
            return null;
        }
        SimpleDateFormat format = new SimpleDateFormat(pattern);
        String dateStr = format.format(date);
        return dateStr;
    }
}